﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Seed.StockLineMvc.Models;
using SqlSugar;

namespace Seed.StockLineMvc.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public JsonResult Query(string smlCode)
        {
            using (var db = SugarDao.GetInstance())
            {
                LongkeCodes code = db.Queryable<LongkeCodes>().FirstOrDefault(it => it.SmlCode == smlCode);
                if (code != null)
                {
                    code.SaleInfo = db.Queryable<SaleCodes>().FirstOrDefault(it => it.BigCode == code.BigCode).SaleInfo;
                    code.Remark = "数据查询成功：";
                }
                else
                {
                    code = new LongkeCodes
                    {
                        Remark = "未查询到数据！"
                    };
                }
                return Json(code);
            }
        }
    }
}